//
//  RHRegistViewController.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/19.
//

#import "RHRegistViewController.h"
#import "NSAttributedString+YYText.h"
#import "YYLabel.h"
#import "RHAuthCodeViewController.h"
#import "BaseModel.h"
#import "RHChioceRegionTypeVC.h"
#import "RHGolbalRegionModel.h"
#import "RHGolbalServerModel.h"
#import "LCMD5Tool.h"
#import "RHBaseWebViewController.h"
#import "NetworkConfig.h"
#import "EnvironmentManage.h"
#import "RHTools.h"

@interface RHRegistViewController ()<QMUITextFieldDelegate>

@property (nonatomic ,strong) UIView *contentView;

@property (nonatomic ,strong)NSMutableArray *TFArr;

@property(nonatomic ,strong)NSArray *countryListArr;

@property ( nonatomic ,strong) QMUIButton *agreeBtn;
@end

@implementation RHRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    if([UserDefaults objectForKey:kCountry]&&[UserDefaults objectForKey:kRegionCode]){
//        [(QMUITextField*)self.TFArr[0] setText:[RHTools getRegionNameWithCode:[UserDefaults objectForKey:kRegionCode]]];//翻译
        [(QMUITextField*)self.TFArr[0] setText:[UserDefaults objectForKey:kCountry]];//不翻译
        [self.registerPara setObject:[UserDefaults objectForKey:kRegionCode] forKey:@"regionCode"];
        [self.registerPara setObject:[UserDefaults objectForKey:kCountry] forKey:@"country"];
    }
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

-(void)setRegisterPara:(NSMutableDictionary *)registerPara
{
    _registerPara = [NSMutableDictionary dictionaryWithDictionary:registerPara];
}

- (void)setupUI{
    _registerPara = [NSMutableDictionary dictionary];
    
    [self.view setBackgroundColor:UIColor.whiteColor];
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    scrollView.backgroundColor = [UIColor clearColor];
    
    if (@available(iOS 11.0, *)){
        scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    kWeakSelf;
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(weakSelf.view);
    }];
    
    _contentView = [[UIView alloc] init];
    _contentView.backgroundColor = kCOLOR_HEX(@"F1FCF3");
    [scrollView addSubview:_contentView];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(scrollView);
        make.width.mas_equalTo(scrollView);
        make.height.greaterThanOrEqualTo(@0.f);//此处保证容器View高度的动态变化 大于等于0.f的高度
    }];
    
    UIView *top_bgView = [[UIView alloc] init];
    [top_bgView setGradientBackgroundWithColors:@[kCOLOR_HEX(@"#6AD68A"),kCOLOR_HEX(@"#5FCCB4")] orientation:GradientOrientationLeftTopToRightBottom];
    [_contentView addSubview:top_bgView];
    [top_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_offset(0);
       
    }];
    
    
    UIImageView *logoImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"login_icon"]];
    [top_bgView addSubview:logoImg];
    [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kSafe_top);
        make.right.mas_offset(0);
        make.size.equalTo(@(CGSizeMake(kScaleW(196), kScaleW(185))));
        make.bottom.mas_offset(-50);
    }];
    
    QMUILabel *welcomeLab = [[QMUILabel alloc]init];
    welcomeLab.text = @"注册Smart Energy账户".rh_localized;
    welcomeLab.numberOfLines = 0;
    welcomeLab.font = [UIFont boldSystemFontOfSize:26];
    welcomeLab.adjustsFontSizeToFitWidth = YES;
    welcomeLab.minimumScaleFactor = 0.8;
    welcomeLab.textColor = kCOLOR_HEX(@"#ffffff");
    welcomeLab.qmui_lineHeight = 45;
    [top_bgView addSubview:welcomeLab];
    [welcomeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(20);
        make.right.mas_offset(-10);
        make.centerY.equalTo(logoImg);
    }];
    
    
    UIView *bg_view = [[UIView alloc] init];
    [bg_view setBackgroundColor:UIColor.clearColor];
    bg_view.layer.cornerRadius = 15;
    bg_view.layer.masksToBounds = YES;
    bg_view.layer.maskedCorners = kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner;
    [_contentView addSubview:bg_view];
    [bg_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(top_bgView.mas_bottom).offset(-75);
       
    }];
    
    UIView *gradientView = kView;
    [gradientView setGradientBackgroundWithColors:@[kCOLOR_HEX_A(@"#FFFFFF",0.5),kCOLOR_HEX_A(@"#FFFFFF",0.8),kCOLOR_HEX_A(@"#FFFFFF",1),kCOLOR_HEX_A(@"#FFFFFF",1)] orientation:GradientOrientationTopToBottom locations:@[@(0),@(0.08),@(0.15),@(1)]];
    [bg_view addSubview:gradientView];
    [gradientView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
    }];
    
    //模糊蒙版本
    UIVisualEffectView *effctVeiw = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect qmui_effectWithBlurRadius:2]];
    [bg_view addSubview:effctVeiw];
    [effctVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];

    NSArray *titles = @[@"国家/地区".rh_localized,@"邮箱".rh_localized,@"账号名称".rh_localized,@"密码".rh_localized,@"确认密码".rh_localized];
    NSArray *placeholders = @[@"请选择国家/地区".rh_localized,@"请输入邮箱".rh_localized,@"请输入账号".rh_localized,@"请输入密码".rh_localized,@"请再次输入密码".rh_localized];
    self.TFArr = [[NSMutableArray alloc]init];
    NSMutableArray *array = [NSMutableArray array];
    [placeholders enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = [[UIView alloc] init];
        [view setBackgroundColor:UIColor.clearColor];
        [bg_view addSubview:view];
        [array addObject:view];
        
        
        QMUILabel *titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#474B53") textAligment:NSTextAlignmentLeft];
        titleLab.text = titles[idx];
        [view addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(10);
            make.left.mas_offset(5);
            make.right.mas_offset(0);
        }];
        
        UIView *textField_bg = [[UIView alloc] init];
        textField_bg.backgroundColor = UIColor.clearColor;
        textField_bg.layer.cornerRadius = 8;
        textField_bg.layer.masksToBounds = YES;
        [view addSubview:textField_bg];
        
        
        [textField_bg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(5);
            make.right.mas_offset(-5);
            make.bottom.mas_offset(0);
            make.top.equalTo(titleLab.mas_bottom).offset(5);
        }];
        
    
        QMUITextField *textField = [[QMUITextField alloc] init];
        textField.tag = idx;
        textField.delegate = self;
        textField.font = kSYSTEMFONT(14);
        textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
        textField.leftViewMode = UITextFieldViewModeAlways;
        [textField setPlaceholder:placeholders[idx]];
        textField.backgroundColor = UIColor.clearColor;
        textField.qmui_borderColor = kCOLOR_HEX(@"#CDD0D6");
        textField.qmui_borderWidth = 1;
        textField.qmui_borderPosition = QMUIViewBorderPositionTop|QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight|QMUIViewBorderPositionBottom;
        textField.layer.cornerRadius = 8;
        [textField_bg addSubview:textField];
        [weakSelf.TFArr addObject:textField];
        //邮箱
        if(idx == 1){//邮箱
            textField.keyboardType = UIKeyboardTypeEmailAddress;
            textField.maximumTextLength = 64;
        }
        if(idx == 3||idx == 4){//密码
            textField.keyboardType = UIKeyboardTypeASCIICapable;
            textField.secureTextEntry = YES;
            textField.maximumTextLength = 16;
            textField.clearButtonMode = UITextFieldViewModeNever;
            textField.keyboardType = UIKeyboardTypeASCIICapable;
            
            //隐藏/显示密码
            QMUIButton *showPwdBtn = [[QMUIButton alloc]init];
            [showPwdBtn setImage:[UIImage imageNamed:@"kwt_show_pwd"] forState:UIControlStateNormal];
            [showPwdBtn setImage:[UIImage imageNamed:@"kwt_show_pwd_s"] forState:UIControlStateSelected];
            [textField_bg addSubview:showPwdBtn];
            [showPwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.height.offset(35);
                make.right.equalTo(textField).offset(-5);
                make.centerY.equalTo(textField);
            }];
            
            [[showPwdBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIButton * _Nullable x) {
                x.selected = !x.selected;
                textField.secureTextEntry = !x.selected;
            }];
        }
        
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(2, 0, 2, 0));
            make.height.offset(44);
        }];
        
        //增加下拉按钮
        if(idx == 0){
            textField.userInteractionEnabled = NO;
            UIImageView *arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nav_arrow_down"]];
            arrowImg.contentMode = UIViewContentModeScaleAspectFit;
            [textField_bg addSubview:arrowImg];
            [arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.height.offset(15);
                make.right.mas_offset(-15);
                make.centerY.mas_offset(0);
            }];
            
            QMUIButton *countryBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
            [textField_bg addSubview:countryBtn];
            [countryBtn addTarget:self action:@selector(getCountryRegionCode) forControlEvents:UIControlEventTouchUpInside];
            [countryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.insets(UIEdgeInsetsZero);
            }];
        }
    }];
    
    [array mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_offset(-10);
    }];
    
    [array mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:10 tailSpacing:40];
    
    
    
    YYLabel *goLoginLab = [[YYLabel alloc] init];
    NSString *tipStr = @"已有账号？去登录".rh_localized;
    //设置多行
    goLoginLab.numberOfLines = 0;
    //这个属性必须设置，多行才有效
    goLoginLab.preferredMaxLayoutWidth = SCREEN_WIDTH-30;
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:tipStr];
    attr.yy_lineSpacing = 8;
    attr.yy_font = [UIFont systemFontOfSize:12];
    //FontColor(@"#3ECE80")
    attr.yy_color = kCOLOR_HEX_A(@"#171A1D", 0.4);
    NSRange range = [tipStr rangeOfString:@"去登录".rh_localized];
    [attr yy_setTextHighlightRange:range color:CFMainColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    
    
    
    //用label的attributedText属性来使用富文本
    goLoginLab.attributedText = attr;
    CGSize maxSize_tip = CGSizeMake(SCREEN_WIDTH-30, MAXFLOAT);
    //计算文本尺寸
    YYTextLayout *layout_tip = [YYTextLayout layoutWithContainerSize:maxSize_tip text:attr];
    goLoginLab.textLayout = layout_tip;
    [bg_view addSubview:goLoginLab];
    [goLoginLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.bottom.mas_offset(-10);
    }];
    
    UIView *foot_view = [[UIView alloc] init];
    [foot_view setBackgroundColor:UIColor.whiteColor];
    [_contentView addSubview:foot_view];
    
    
    QMUIButton *registBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [registBtn setTitle:@"下一步".rh_localized forState:UIControlStateNormal];
    [registBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [registBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [registBtn setBackgroundColor:CMainColorGreen];
    [registBtn.layer setCornerRadius:5];
    [registBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [foot_view addSubview:registBtn];
    
    QMUIButton *agreeBtn = [[QMUIButton alloc]init];
    [agreeBtn setImage:[UIImage imageNamed:@"ugrade_cancel"] forState:UIControlStateNormal];
    [agreeBtn setImage:[UIImage imageNamed:@"ugrade_select"] forState:UIControlStateSelected];
    [foot_view addSubview:agreeBtn];
    self.agreeBtn = agreeBtn;
    [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(registBtn.mas_bottom).offset(25);
        make.left.mas_offset(15);
        make.width.height.offset(25);
    }];
    
    YYLabel *contentL = [[YYLabel alloc] init];
    NSString *str = @"通过注册即代表您同意Smart Energy的服务条款和隐私政策".rh_localized;
    //设置多行
    contentL.numberOfLines = 0;
    //这个属性必须设置，多行才有效
    contentL.preferredMaxLayoutWidth = SCREEN_WIDTH-30-25;
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
    attri.yy_lineSpacing = 8;
    //attri.yy_alignment = NSTextAlignmentCenter;
    attri.yy_font = [UIFont systemFontOfSize:12];
    //FontColor(@"#3ECE80")
    attri.yy_color = kCOLOR_HEX_A(@"#171A1D", 0.4);
    NSRange range1 = [str rangeOfString:@"服务条款".rh_localized];
    NSRange range2 = [str rangeOfString:@"隐私政策".rh_localized];

    [attri yy_setTextHighlightRange:range1 color:CFMainColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        RHBaseWebViewController *vc = [[RHBaseWebViewController alloc] init];
//        [vc setLocalHtml:@"terms_of_use"];
        vc.urlStr = @"https://www.ruihenergy.com/terms_of_use";
        vc.navTitle = @"服务条款".rh_localized;
        [weakSelf.navigationController pushViewController:vc animated:YES];
   
        
    }];
    
    [attri yy_setTextHighlightRange:range2 color:CFMainColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        //隐私协议
        RHBaseWebViewController *vc = [[RHBaseWebViewController alloc] init];
//        [vc setLocalHtml:@"privacy_policy"];
        vc.urlStr = @"https://www.ruihenergy.com/privacy_policy";
        vc.navTitle = @"隐私政策".rh_localized;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    
    //用label的attributedText属性来使用富文本
    contentL.attributedText = attri;
    CGSize maxSize = CGSizeMake(SCREEN_WIDTH-30, MAXFLOAT);
    //计算文本尺寸
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:attri];
    contentL.textLayout = layout;
    //CGFloat introHeight = layout.textBoundingSize.height;
    
    [foot_view addSubview:contentL];

    
    
    [registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.mas_equalTo(50);
        make.top.mas_offset(25);
    }];
    
    [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(agreeBtn.mas_right);
        make.centerY.equalTo(agreeBtn);
        make.right.equalTo(registBtn);
        make.height.mas_equalTo(50);
        make.bottom.offset(kSafe_bottom>0?-kSafe_bottom:-15);
    }];
    
    
    [foot_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.right.mas_offset(0);
        make.top.equalTo(bg_view.mas_bottom);
        make.bottom.mas_offset(0);
       
    }];

    
    [[registBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
      
        [weakSelf registerAction];
       
    }];
    
    
    QMUIButton *backBtn = [[QMUIButton alloc]init];
    [backBtn setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    [self.view addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(35);
        make.left.mas_offset(8);
        make.top.mas_offset(kSafe_top);
    }];
    [[backBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    
    [[agreeBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        x.selected = !x.selected;
    }];
    
    //切换环境
    if((!Environment)&&Project_Test){
        QMUIButton *enironmentBtn = [[QMUIButton alloc]init];
        NSString *curEnironment = [[EnvironmentManage sharedEnvirManage] getCurrentEnvironment];
        [enironmentBtn setTitle:curEnironment forState:UIControlStateNormal];
        enironmentBtn.titleLabel.font = kSYSTEMFONT(15);
        enironmentBtn.imagePosition = QMUIButtonImagePositionRight;
        [enironmentBtn setTitleColor:kCOLOR_HEX(@"000000") forState:UIControlStateNormal];
        [enironmentBtn setImage:[UIImage imageNamed:@"nav_arrow_down"] forState:UIControlStateNormal];
        [foot_view addSubview:enironmentBtn];
        [enironmentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_offset(0);
            make.bottom.equalTo(registBtn.mas_top).offset(-5);
            make.width.offset(200);
            make.height.offset (35);
        }];
        [[enironmentBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            NSArray *eniArr = @[@"开发环境",@"测试环境",@"验收环境",@"线上环境"];
            RHChioceRegionTypeVC *choiseVC = [[RHChioceRegionTypeVC alloc]initWithData:eniArr];
            choiseVC.curContent = [[EnvironmentManage sharedEnvirManage] getCurrentEnvironment];
            choiseVC.selectBlock = ^(NSInteger index) {
                [enironmentBtn setTitle:eniArr[index] forState:UIControlStateNormal];
                [[EnvironmentManage sharedEnvirManage]changeEnvironment:index];
            };
            [[RHWindowTipManage shareWindowTipManage] showWithController:choiseVC];
        }];
    }
}

#pragma mark ---- 点击下一步
-(void)registerAction
{
    RHAuthCodeViewController *vc = [[RHAuthCodeViewController alloc] init];
    vc.userInfo = self.registerPara;
    
    if (self.agreeBtn.selected == NO) {
        [QMUITips showInfo:@"请同意服务条款和隐私政策".rh_localized];
        return;
    }
    for (QMUITextField *tf in self.TFArr) {
        if(tf.text.length==0){
            [QMUITips showError:@"请输入完整信息".rh_localized];
            return;
        }
    }
    if (![[(QMUITextField*)self.TFArr[3] text] isEqualToString:[(QMUITextField*)self.TFArr[4] text]]){
        [QMUITips showError:@"两次输入的密码不一致".rh_localized];
        return;
    }
    //邮箱校验
    NSString *email =  [(QMUITextField*)self.TFArr[1] text];
    if(![NSString isValidateEmail:email]){
        [QMUITips showError:@"邮箱格式错误".rh_localized];
        return;
    }
    //用户名校验
    NSString *userName =  [(QMUITextField*)self.TFArr[2] text];
    if(![NSString validateUserName:userName]){
        [QMUITips showError:@"账号名称请输入3到20位数字,字母或下划线".rh_localized];
        return;
    }
     //密码校验
     NSString *password =  [(QMUITextField*)self.TFArr[3] text];
     if(![NSString validatePassword:password]){
         [QMUITips showError:@"密码长度为8 ~ 16，必须包含大写字母、小写字母和数字".rh_localized];
         return;
     }
    
   //注册用户 参数
    NSMutableDictionary *registerDic = [[NSMutableDictionary alloc]initWithDictionary:@{
        @"email":email,
        @"userName":userName,
        @"password":[LCMD5Tool md5HexDigest:password]
    }];
    [self.registerPara addEntriesFromDictionary:registerDic];
    NSLog(@"----->请求参数:%@",self.registerPara);
    
    //根据国家编码获取区域服务器
    [self getServerInfoFromCountryCode];

}

//获取国家所有编码
-(void)getCountryRegionCode
{
    //根据全球国家编码
    [QMUITips showLoadingInView:self.view];
    [RHGolbalRegionModel startWithBaseUrl:[EnvironmentManage sharedEnvirManage].getBaseAPIUrl APIKey:G_getCountries argument:@{} requestMethod:RequestMethodPOST requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
            self.countryListArr = resultModel.data;
            [self showCountryList];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
    
}


#pragma mark ---- 根据国家编码获取区域服务器
-(void)getServerInfoFromCountryCode
{
    [QMUITips showLoading:@"获取地区服务器...".rh_localized inView:self.view];
    NSDictionary *para = @{@"countryCode":self.registerPara[@"regionCode"],
                           @"brandId":[NetworkConfig sharedConfig].brandID,
                           @"requestType":@(1)
    };
    [RHGolbalServerModel startWithBaseUrl:[EnvironmentManage sharedEnvirManage].getBaseAPIUrl APIKey:G_getServerInfo argument:para requestMethod:RequestMethodPOST requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
            RHGolbalServerModel *serverModel = [resultModel.data yy_modelCopy];
            [NetworkConfig sharedConfig].baseUrl = serverModel.apiAddress;
            
            
    #pragma mark ----        //获取验证码 参数
            NSDictionary *para = @{@"sendEmail":[(QMUITextField*)self.TFArr[1] text],@"action":@"新用户注册,获取验证码"};
            [QMUITips showLoading:@"获取验证码".rh_localized inView:self.view];
            [BaseModel startWithCompletionAPIKey:H_sendCodeNoToken header:@{} argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
                if(resultModel.code == 200){
                    [QMUITips showSucceed:@"验证码已发送".rh_localized];
                    RHAuthCodeViewController *vc = [[RHAuthCodeViewController alloc] init];
                    vc.userInfo = self.registerPara;
                    [self.navigationController pushViewController:vc animated:YES];
                }
            } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {

            }];
            
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}


#pragma mark ----- action ---

-(void)showCountryList
{
    if(self.countryListArr.count == 0){
        [QMUITips showError:@"没有数据".rh_localized];
        return;
    }
    NSMutableArray *countryArr = [NSMutableArray array];
    for (int i = 0; i<self.countryListArr.count; i++) {
        RHGolbalRegionModel *model = self.countryListArr[i];
//        [countryArr addObject:[RHTools getRegionNameWithCode:model.countryCode]];//翻译
        [countryArr addObject:model.countryName];//不翻译
    }
    RHChioceRegionTypeVC *vc = [[RHChioceRegionTypeVC alloc] initWithData:countryArr];
    QMUITextField *tf = (QMUITextField*)self.TFArr[0];
    vc.curContent = tf.text;
    [[RHWindowTipManage shareWindowTipManage] showWithController:vc];
    kWeakSelf;
    vc.selectBlock = ^(NSInteger index) {
        QMUITextField *tf = (QMUITextField*)weakSelf.TFArr[0];
        RHGolbalRegionModel *model = weakSelf.countryListArr[index];
//        tf.text = [RHTools getRegionNameWithCode:model.countryCode];//翻译
        tf.text = model.countryName;//不翻译
        //国家区域编码
        [weakSelf.registerPara setObject:model.countryName forKey:@"country"];
        [weakSelf.registerPara setObject:model.countryCode forKey:@"regionCode"];
    };
}



@end
